<?php

namespace App\Http\Controllers;

use App\Models\Evaluate;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class EvaluateController extends BaseController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     * 评价列表
     */
    public function index(Request $request)
    {
        $param = $request->input();
        if (empty($param['goods_id'])) {
            return $this->ResultJson(0, '商品ID不能为空!', []);
        }
        if (empty($param['types'])) {
            return $this->ResultJson(0, '类型不能为空!', []);
        }
        $list = (new Evaluate())->getEvaluateListData($param);
        if (!empty($list)) {
            return $this->ResultJson(1, '获取成功!', $list);
        }
        return $this->ResultJson(0, '暂无数据!', []);
    }


    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     * 工作室评价列表
     */
    public function workAllList(Request $request)
    {
        $param = $request->input();
        if (empty($param['work_id'])) {
            return $this->ResultJson(0, '工作室ID不能为空!', []);
        }
//        if (empty($param['types'])) {
//            return $this->ResultJson(0, '类型不能为空!', []);
//        }
        $list = (new Evaluate())->getAllEvaluateListData($param);
        if (!empty($list)) {
            return $this->ResultJson(1, '获取成功!', $list);
        }
        return $this->ResultJson(0, '暂无数据!', []);
    }





    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     * 添加评论
     */
    public function create(Request $request)
    {
        $param = $request->input();
        if (empty($param['user_id'])) {
            return $this->ResultJson(0, '用户ID不能为空!', []);
        }
        if (empty($param['goods_id'])) {
            return $this->ResultJson(0, '商品ID不能为空!', []);
        }
        if (empty($param['order_id'])) {
            return $this->ResultJson(0, '订单ID不能为空!', []);
        }
        if (empty($param['service_score'])) {
            return $this->ResultJson(0, '服务态度不能为空!', []);
        }
        if (empty($param['content'])) {
            return $this->ResultJson(0, '评论内容不能为空!', []);
        }
        if (empty($param['types'])) {
            return $this->ResultJson(0, '评论类型不能为空!', []);
        }
        if ($param['types'] == 2) {
            if (empty($param['logis_score'])) {
                return $this->ResultJson(0, '物流速度评分不能为空!', []);
            }
            if (empty($param['delivery_score'])) {
                return $this->ResultJson(0, '服务态度评分不能为空!', []);
            }
        }
        $course = (new Evaluate())->addEvaluateContent($param);
        if (is_array($course)) {
            return $this->ResultJson(1, '评价成功!', $course);
        }
        return $this->ResultJson(0, $course, []);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\Evaluate  $evaluate
     * @return \Illuminate\Http\Response
     */
    public function show(Request $request)
    {

    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\Evaluate  $evaluate
     * @return \Illuminate\Http\Response
     */
    public function edit(Evaluate $evaluate)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Evaluate  $evaluate
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Evaluate $evaluate)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Evaluate  $evaluate
     * @return \Illuminate\Http\Response
     */
    public function destroy(Evaluate $evaluate)
    {
        //
    }
}
